import { createRouter, createWebHashHistory, createWebHistory, Router } from 'vue-router'
// import { defineAsyncComponent } from 'vue'
import routes from './routes'

const router: Router = createRouter({
  history: createWebHashHistory(),
  routes,
})

router.beforeEach((to, form, next) => {
  document.title = `${to.meta.title}`
  if (to.name !== 'Login') {
    let userInfo = sessionStorage.getItem('loginUserInfo')
    if (!userInfo) {
      next({ name: 'Login' })
    } else {
      next()
    }
  } else {
    next()
  }
  // for test ignore the authority
  // next()
})

export default router
